"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameImgHelper = void 0;
const path = require("path");
const Logger_1 = require("../../engine/utils/Logger");
const fs = require('fs');
class GameImgHelper {
    static base64_to_imgurl(userid, upload_pic_type, imgData) {
        let base64 = imgData.replace(/^data:image\/\w+;base64,/, ""); //去掉图片base64码前面部分data:image/png;base64
        if (base64.length > 0 && base64 != 'null') {
            let dataBuffer = Buffer.from(base64, 'base64'); //把base64码转成buffer对象，
            return this.buffer_to_imgurl(userid, upload_pic_type, dataBuffer);
        }
    }
    static buffer_to_imgurl(userid, upload_pic_type, dataBuffer) {
        let baseUploadPath = path.resolve() + "/public/upload/";
        if (!fs.existsSync(baseUploadPath)) {
            fs.mkdirSync(baseUploadPath);
        }
        // let fileName: string = userid + "-" + upload_pic_type+"-"+DateUtil.formatDateStr4(DateUtil.now()) + ".jpg"
        let fileName = userid + "-" + upload_pic_type + ".jpg";
        let filePath = baseUploadPath + "/" + fileName;
        fs.writeFile(filePath, dataBuffer, function (err) {
            if (err) {
                Logger_1.Logger.error(err);
            }
        });
        // let serverConfig: ServerConfig = ServerConfig.randomWebServer()
        // let imgurl: string = serverConfig.getHttpUrl() + "/upload/" + fileName;
        // Logger.log("upload========imgurl====", imgurl);
        // return imgurl;
        return "";
    }
}
exports.GameImgHelper = GameImgHelper;
